<?php

class Survey{
	
	function _construct(){
		/*$this->id = $id;
		$query = mysql_query("SELECT * FROM  `survey` WHERE `id` = '$id'") or die (mysql_error);
		$survey = mysql_fetch_object($query);
		
		if($survey!=''){
			$this->name = $survey->survey_name;
			$this->title = $survey->survey_title;
			$this->welcome_message = $survey->welcome_message;
			$this->confirmation_message = $survey->confirmation_message;
		}*/
	}

	
	public function getSurvey($id){
		$this->id = $id;
		$query = mysql_query("SELECT * FROM  `survey` WHERE `id` = '$id'") or die (mysql_error);
		$s = mysql_fetch_object($query);
		
		$survey['name']= $s->survey_name;
		$survey['title']=$s->survey_title;
		$survey['welcome_message']=$s->welcome_message;
		$survey['confirmation_message']= $s->confirmation_message;
		
		
		if($survey){
			return $survey;
		}else{
			return false;
		}
	}
	
	public function createSurvey($data){
    $instructor = $_SESSION['logged_in'];	
	$test = "SELECT * FROM `survey` WHERE `name` = '{$data['survey_name']}' AND `instructor_id` = '$instructor';";
    $check = mysql_query($test)or die ('TEST insert Survey'.mysql_error());
    $rows = mysql_num_rows($check);
      	
    if($rows ==0){ 
 	$sql = "INSERT INTO `survey` (`user_id`,`name`,`title`,`subtitle`,`welcome_message`,`confirmation_message`,
	                                            `date_created`,`date_start`,`date_end`,`status`)
			VALUES (
            '{$data['instructor_id']}',
			'{$data['survey_name']}',
			'{$data['survey_title']}',
			'{$data['survey_welcome_message']}',
			'{$data['survey_confirmation_message']}'
			);";

	$result = mysql_query($sql) or die('Create Survey: '.mysql_error());

	return true;
    }else{
    	return false;
    }
	
}
}

?>